Skip to content

Unreachable code in shard.py #10144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
GDOlivercoding opened this issue Mar 16, 2025 · 1 comment
Open
3 tasks done

Unreachable code in shard.py #10144

GDOlivercoding opened this issue Mar 16, 2025 · 1 comment
Labels
unconfirmed bug A bug report that needs triaging

Comments

@GDOlivercoding
Copy link

GDOlivercoding commented Mar 16, 2025

Summary

I found an unreachable error case in discord.shard or shard.py

Reproduction Steps

Hello! I found an unreachable error case in https://github.com/Rapptz/discord.py/blob/master/discord/shard.py#L520-523 this snippet here when i was browsing the library code,

the snippet is as follows:

                   if item.error.code != 1000:
                        raise item.error
                    if item.error.code == 4014:
                        raise PrivilegedIntentsRequired(item.shard.id) from None

as you can see, the second error case is completely unreachable, as in order to reach there .code must be 4014, which it cannot

further more, setting type checker mode to strict will show us this error:

Condition will always evaluate to False since the types "Literal[1000]" and "Literal[4014]" have no overlap

https://github.com/Rapptz/discord.py/blob/master/discord/shard.py#L151-L157
here is an example where it is correctly written

Minimal Reproducible Code

code = 4014
if item.error.code != 1000:
    raise ValueError("generic raise")
if item.error.code == 4014:
    raise ValueError("specific raise")

Expected Results

Unrelated

Actual Results

Unrelated

Intents

Unrelated

System Information

  • Python v3.12.8-final
  • discord.py v2.5.2-final
  • aiohttp v3.9.3
  • system info: Windows 10 10.0.19045

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

@GDOlivercoding GDOlivercoding added the unconfirmed bug A bug report that needs triaging label Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

2 participants
@GDOlivercoding and others